<template>
    <div class="photoShare-container">
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl"
                 class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item',item.id==0?'mui-active':'']" v-for="item in cates" :key="item.id"
                       @click="getPhoto(item.id)">
                        {{item.name}}
                    </a>
                </div>
            </div>
            <ul class="photo-list">
                <router-link v-for="(item,i) in photoList.images" :key="i" :to="'/home/photoInfo/'+photoList.categoryId" tag="li">
                    <img v-lazy="item" :key="item">
                    <div class="info">
                        <h4>{{photoList.name }}</h4>
                        <div>
                            {{photoList.address}}
                            {{photoList.businessHours}}
                            {{photoList.link}}
                        </div>
                    </div>
                </router-link>
            </ul>

        </div>
    </div>
</template>

<script>
    import mui from '../../lib/mui/js/mui.min.js';
    import {Toast} from 'mint-ui';

    export default {
        data() {
            return {
                cates: [],
                photoList: [],
                i: 70
            }
        },
        created() {
            this.getCates();
            this.getPhoto(3);
        },
        mounted() {
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
        methods: {
            getCates() {
                this.$http.get('categories').then(result => {
                    if (result.status === 200) {
                        result.data.unshift({name: '全部', id: 0});
                        this.cates = result.data;
                    } else {
                        Toast('网络较差，请稍候再试')
                    }
                });
            },
            getPhoto(catId) {
                if (catId === 0 || catId > 4) {
                    catId = 1;
                    this.$http.get('categories/' + catId + '/shops').then(result => {
                        if (result.status === 200) {
                            if (this.i < 80) {
                                this.i++;
                                console.log(this.i);
                                const index = this.i;
                                this.photoList = result.data[index];
                            } else if (this.i >= 80) {
                                this.i = 60;
                            }
                        } else {
                            Toast('网络较差，请稍候再试')
                        }
                    })
                } else {
                    this.$http.get('categories/' + catId + '/shops').then(result => {
                        if (result.status === 200) {
                            this.photoList = result.data[catId]

                        } else {
                            Toast('网络较差，请稍候再试')
                        }
                    })
                }

            }
        },
    }

</script>

<style lang="less" scoped>
    .photoShare-container {
        * {
            touch-action: pan-y; //新的样式，只能在chrome生效
        }

        .photo-list {
            padding: 10px;
            margin: 0 ;
            list-style: none;
            li {
                background-color: #ccc;
                text-align: center;
                margin-bottom: 7px;
                box-shadow: 0 0 3px #000;
                position: relative;
                img {
                    width: 100%;
                    vertical-align: middle;
                }

                img[lazy=loading] {
                    width: 40px;
                    height: 300px;
                    margin: auto;
                }
            }
        }

        .info {
            color: #fff;
            text-align: left;
            position: absolute;
            bottom: 0;
            background-color: rgba(0, 0, 0, .5);
            max-height: 90px;
            padding-bottom: 3px;

            div {
                font-size: 13px;
            }
        }

        .mui-slider {
            #sliderSegmentedControl {
                position: fixed;
                background-color: rgba(255, 255, 255, .8);
                top:40px;
                &:after {
                    display: block;
                    content: "";
                    height: 1px;
                    background-color: #e2e2e2;
                    position: fixed;
                    top: 76px;
                    left: 0;
                    width: 100%;
                }
            }
        }


    }


</style>